package com.wuxiaofan.secondkill.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuxiaofan.secondkill.client.Idgenerator;
import com.wuxiaofan.secondkill.entity.Goods;
import com.wuxiaofan.secondkill.entity.custom.GoodsCustom;
import com.wuxiaofan.secondkill.mapper.GoodsMapper;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class GoodsService {
    @Autowired
    private GoodsMapper tGoodsMapper;
    @Resource
    private Idgenerator idgenerator;

    public Goods findById(String id){
        return tGoodsMapper.selectById(id);
    }

    public GoodsCustom findCountByMap(Map paraMap){
        return tGoodsMapper.findCountByMap(paraMap);
    }

    public GoodsCustom findGroupByMap(Map paraMap){
        return tGoodsMapper.findGroupByMap(paraMap);
    }

    public List<GoodsCustom> findByMap(Map paraMap){
        return tGoodsMapper.findByMap(paraMap);
    }

    public Page<GoodsCustom> findByMap(Map paraMap, Page page){
        return page.setRecords(tGoodsMapper.findByMap(paraMap,page));
    }


    public void updateMapById(Map paraMap){
        tGoodsMapper.updateMapById(paraMap);
    }
    public void delById(String id){
        tGoodsMapper.deleteById(id);
    }

    public Goods save(Goods tGoods){
        tGoods.setId(idgenerator.getId());
        tGoodsMapper.insert(tGoods);
        return tGoods;
    }

}
